/**
 * 定义季度报表模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.zhuhai.reportData.quarterDataManager', ['water.apps.common.report.reportFormBase',
	                                                                          'water.common.dateUtil']);
	
	module.controller('quarterDataMonthManagerController',function($scope,$zhuhaiMonitorDataService,$controller,$dateUtil){

		var control = $controller("commonReportFormController",{$scope:$scope});
		$scope.stadardData={};
		var TwoTypeWaterStardard = {"065":'0.2~0.5(湖、库)',"060":'0.15~0.5',"ss_zhuodu":'',"101":'0.02~0.1',"111":'2~4',"001":'6~9',"cond":'',"do":'6~7.5',"phtem":''};
		var threeTypeWaterStardard = {"065":'0.5~1(湖、库)',"060":'0.5~1',"ss_zhuodu":'',"101":'0.1~0.2',"111":'4~6',"001":'6~9',"cond":'',"do":'5~6',"phtem":''};
		var fourTypeWaterStardard = {"065":'1~1.5(湖、库)',"060":'1~1.5',"ss_zhuodu":'',"101":'0.2~0.3',"111":'6~10',"001":'6~9',"cond":'',"do":'3~5',"phtem":''};
		$scope.stadardData.TwoTypeWaterStardard = TwoTypeWaterStardard;
		$scope.stadardData.threeTypeWaterStardard = threeTypeWaterStardard;
		$scope.stadardData.fourTypeWaterStardard = fourTypeWaterStardard;
		$scope.item = "项目";
		$scope.unit = "单位";
		$scope.Stadard_II = "地表水标准值Ⅱ类";
		$scope.Stadard_III = "地表水标准值Ⅲ类";
		$scope.Stadard_IV = "地表水标准值Ⅳ类";
		
		/**
		 * 年选择下拉数据
		 */
		$scope.yearlist = [{name:'2016年',value:2016},{name:'2017年',value:2017}];
		/**
		 * 选择的年份
		 */
		$scope.selectYear;
		/**
		 * 选择的季度
		 */
		$scope.selectQuarter;
		/**
		 * 季度选择下拉数据
		 */
		$scope.quarterslist=[
		                 {name:"第1季度",value:1},
		                 {name:"第2季度",value:2},
		                 {name:"第3季度",value:3},
		                 {name:"第4季度",value:4}
		                ];
		
		$scope.dataAPIName = 'getQuarterReport';
		$scope.dataExportAPIName = "exportQuarterExcel";
		/**
		 * 季度选择事件
		 */
		$scope.onQuarterSelected = function(){
			$scope.getQueryObject();
		}
		/**
		 * 获取查询参数
		 */
		$scope.getQueryObject = function(){
			var startMonth = ($scope.selectQuarter - 1) * 3 + 1;
			var startDateStr = $scope.selectYear + "-" + startMonth + "-1 00:00:00";
			var startDate = $dateUtil.createDate(startDateStr);
			var endDate = $dateUtil.addDay($dateUtil.addMonth(startDate,3),-1);
			var endDateStr = $dateUtil.formatDate(endDate);
			
			var parmsStr = $scope.selectedModel.parmToChecksStr;
			var queryObject = {
					"MN":$scope.selectedModel.MN,
					"PARMS":parmsStr,
					"START":startDateStr,
					"END":endDateStr
				};
			return queryObject;
		}
		
		function _init(){
			var date = new Date();
			var month = date.getMonth() + 1;
			if(month <= 3){
				$scope.selectQuarter = 1;
			}
			else if(month <= 6){
				$scope.selectQuarter = 2;
			}
			else if(month <= 9){
				$scope.selectQuarter = 3;
			}
			else if(month <= 12){
				$scope.selectQuarter = 4;
			}
			$scope.selectYear = date.getFullYear();
		}
		/**
		 * 导出excel
		 */
		$scope.onExportExcelClick = function(){
			var queryObj = $scope.getQueryObject(true);
			$zhuhaiMonitorDataService[$scope.dataExportAPIName](queryObj);
		}
		
		$scope.getReport = function(queryObject){
			$zhuhaiMonitorDataService[$scope.dataAPIName](queryObject).then(function(data){
				$scope.data = data;
			});
			$scope.onTBClick();
		}
		
		_init();
		
	});
}(window, angular));